package com.yufubao.service.service.common.util;

import com.google.common.collect.ImmutableMap;
import com.yufubao.model.pojo.applet.product.SupplierInfoEntity;
import com.yufubao.service.service.applet.authorization.UserService;
import com.yufubao.service.service.applet.product.SupplierProductCategoryService;
import com.yufubao.service.service.popularize.authorization.BeesInfoService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Objects;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/9/18 16:15
 */
@Component
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class ServiceUtil {


    private final UserService userService;
    private final SupplierProductCategoryService supplierProductCategoryService;
    private final BeesInfoService beesInfoService;


    /**
     * 用户名、分类名、小蜜蜂名
     * @param supplierInfo
     * @return
     */
    public  Map<String, String> getName(SupplierInfoEntity supplierInfo) {
        String nickname = userService.getById(supplierInfo.getUserId()).getNickname();

        String categoryName = supplierProductCategoryService.getById(supplierInfo.getCategoryId()).getName();

        String beesName = "";
        if (!Objects.isNull(supplierInfo.getBeesId())) {
            beesName = beesInfoService.getById(supplierInfo.getBeesId()).getNickname();
        }

        return ImmutableMap.of(
                "userName", nickname,
                "categoryName", categoryName,
                "beesName", beesName);
    }


}
